﻿#region COPYRIGHT
//--------------------------------------------------------------------------------
// <copyright file="WidgetCollection.cs" company="starLiGHT Entertainment Studios">
//    Copyright (c) 2011 
//       Roland Rosenkranz (Glatzemann@email.de)
// </copyright>
// <license>
//   This file is part of starLiGHT.GUI.
//
//   It is released under the Microsoft Public License (Ms-PL).
//
//   You should have received a copy of the Microsoft Public License
//   along with starLiGHT.GUI. If not, see http://sle.codeplex.com/license.
//    
//   ADDITIONAL (commercial) LICENSES for starLiGHT.GUI are available on request.
// </license>
// <version>
// **************[ starLiGHT.Engine SVN ]**********************
// * $Rev::                       $:  Revision of last commit *
// * $Author::                    $:  Author of last commit   *
// * $Date::                      $:  Date of last commit     *
// ************************************************************
// </version>
//--------------------------------------------------------------------------------
#endregion

namespace starLiGHT.GUI
{
#region Using Statements
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Text;
    using starLiGHT.GUI.Widgets;
#endregion

    public class WidgetCollection : List<Widget>
    {
        #region Private Members
        private Widget creator;
        #endregion

        #region Constructors
        public WidgetCollection(Widget creator)
        {
            this.creator = creator;
        }
        #endregion

        #region Events
        public event EventHandler WidgetAdded;

        public event EventHandler WidgetRemoved;
        #endregion

        public new void Add(Widget w)
        {
            base.Add(w);
            w.Parent = this.creator;
            this.OnWidgetAdded(w);
        }

        public new bool Remove(Widget w)
        {
            if (base.Remove(w))
            {
                w.Parent = null;
                this.OnWidgetRemoved(w);

                return true;
            }

            return false;
        }

        public virtual void OnWidgetAdded(Widget w)
        {
            if (this.WidgetAdded != null)
            {
                this.WidgetAdded(w, EventArgs.Empty);
            }
        }

        public virtual void OnWidgetRemoved(Widget w)
        {
            if (this.WidgetRemoved != null)
            {
                this.WidgetRemoved(w, EventArgs.Empty);
            }
        }
    }
}
